//
//  UIViewAnimations2.m
//  Animations飞机
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "UIViewAnimations2.h"

@interface UIViewAnimations2 ()
@property (weak, nonatomic) IBOutlet UIImageView *plane;

@end

@implementation UIViewAnimations2

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    // UIView 隐式动画
    
    // 方式1
    //    [UIView beginAnimations:nil context:nil];
    //    [UIView setAnimationDuration:1];
    //    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    ////    [UIView setAnimationRepeatAutoreverses:YES];
    //    [UIView setAnimationRepeatCount:NSNotFound];
    //
    //    // 中止值
    //    CGPoint center = self.plane.center;
    //    center.x += 100;
    //    center.y += 100;
    //    self.plane.center = center;
    //
    //    [UIView commitAnimations];
    
    // 方式2
    [UIView animateWithDuration:1 // 动画事件
                          delay:0 // 延迟
         usingSpringWithDamping:0.1 // 阻尼系数(阻力)
          initialSpringVelocity:5  //
                        options:UIViewAnimationOptionCurveLinear
                     animations:
     ^{
         CGPoint center = self.plane.center;
         center.x += 100;
         center.y += 200;
         self.plane.center = center;
         
     } completion:^(BOOL finished)
     {
         
     }];
}

@end
